package com.xja.friend.service.impl;

import com.xja.friend.entity.Message;
import com.xja.friend.mapper.MessageMapper;
import com.xja.friend.service.MessageService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Resource
    private MessageMapper messageMapper;

    @Override
    @Transactional(propagation= Propagation.REQUIRED)
    public int insert(Message record) throws Exception {
        return messageMapper.insert(record);
    }

    @Override
    @Transactional(readOnly = true)//只读事务
    public Message selectByPrimaryKey(String id) throws Exception {
        return messageMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED)
    public int updateByPrimaryKey(Message record) throws Exception {
        return messageMapper.updateByPrimaryKey(record);
    }

    @Override
    @Transactional(readOnly = true)//只读事务
    public Message selectbyFromid(Integer fromid) throws Exception {
        return messageMapper.selectbyFromid(fromid);
    }

    @Override
    @Transactional(readOnly = true)//只读事务
    public List<Message> findHDXinXi(@Param("fromid") Integer fromid, @Param("toid") Integer toid) throws Exception {

        return messageMapper.findHDXinXi(fromid,toid);
    }
}
